﻿using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.LIB;

namespace YArchitech.HVAC
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class HYCalcDuctFlow : IExternalCommand
	{
		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			if (commandData == null)
			{
				throw new System.ArgumentNullException("commandData", "is null");
			}
			try
			{
				if (HYCalcDuctFlow.hWndRevit == null)
				{
					HYCalcDuctFlow.hWndRevit = new YJKWindowHandle(Process.GetCurrentProcess().MainWindowHandle);
				}
				new CalcDuctForm().Show(HYCalcDuctFlow.hWndRevit);
			}
			catch (Exception)
			{
				throw;
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public static YJKWindowHandle hWndRevit;
	}
}
